document.addEventListener('DOMContentLoaded', function() {
    // 获取DOM元素
    const shopNameElement = document.getElementById('shop-name');
    const scheduleContent = document.getElementById('schedule-content');
    
    // 内联商家名称数据
    const shopName = "佳剪发艺";
    
    // 内联营业时间数据
    const businessHoursData = `2025-06-08 9:30-19:00
2025-06-09 9:30-19:00
2025-06-10 休息
2025-06-11 9:30-19:00
2025-06-12 9:30-19:00
2025-06-13 9:30-20:00
2025-06-14 10:00-18:00`;
    
    // 显示商家名称
    displayShopName();
    
    // 显示营业时间数据
    displayBusinessHours();
    
    /**
     * 显示商家名称
     */
    function displayShopName() {
        shopNameElement.textContent = shopName;
        document.title = shopName + ' - 营业时间表';
    }
    
    /**
     * 显示营业时间数据
     */
    function displayBusinessHours() {
        const lines = businessHoursData.trim().split('\n');
        if (lines.length === 0) {
            scheduleContent.innerHTML = '<div class="no-data">暂无营业时间数据</div>';
            return;
        }
        
        // 清除加载提示
        scheduleContent.innerHTML = '';
        
        // 最多显示7天
        const maxDays = Math.min(lines.length, 7);
        const today = new Date();
        today.setHours(0, 0, 0, 0); // 设置为今天的0点
        
        for (let i = 0; i < maxDays; i++) {
            const line = lines[i].trim();
            if (!line) continue;
            
            const parts = line.split(' ');
            if (parts.length < 2) continue;
            
            const dateStr = parts[0];
            const hoursStr = parts.slice(1).join(' ');
            
            // 解析日期
            const dateParts = dateStr.split('-');
            if (dateParts.length !== 3) continue;
            
            const year = parseInt(dateParts[0]);
            const month = parseInt(dateParts[1]) - 1; // 月份从0开始
            const day = parseInt(dateParts[2]);
            
            const date = new Date(year, month, day);
            const dayOfWeek = getDayOfWeek(date);
            
            // 判断营业状态
            const isOpen = hoursStr !== '休息';
            const status = isOpen ? '营业中' : '休息';
            const statusClass = isOpen ? 'status-open' : 'status-closed';
            
            // 检查是否是今天
            const isToday = date.getTime() === today.getTime();
            const todayClass = isToday ? 'today' : '';
            
            // 创建行
            const row = document.createElement('div');
            row.className = `schedule-row ${todayClass}`;
            row.innerHTML = `
                <div class="date-cell">${dateStr}</div>
                <div class="day-cell">${dayOfWeek}</div>
                <div class="hours-cell">${hoursStr}</div>
                <div class="status-cell ${statusClass}">${status}</div>
            `;
            
            scheduleContent.appendChild(row);
        }
    }
    
    /**
     * 获取星期几
     * @param {Date} date 日期对象
     * @returns {string} 星期几的中文表示
     */
    function getDayOfWeek(date) {
        const days = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
        return days[date.getDay()];
    }
}); 